package spring_transaction;

import java.util.Arrays;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.zzuzhm.transaction.tx.BookShopDao;
import cn.zzuzhm.transaction.tx.BookShopService;
import cn.zzuzhm.transaction.tx.Cashier;

public class Transation {
	
	private ApplicationContext applicationContext;
	private BookShopDao bookShopDao;
	private BookShopService bookShopService;
	private Cashier cashier;
	
	{
		applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		bookShopDao = applicationContext.getBean(BookShopDao.class);
		bookShopService = (BookShopService) applicationContext.getBean("bookShopService");
		cashier = applicationContext.getBean(Cashier.class);
	}
	@Test
	public void testTransation(){
		System.out.println(bookShopDao.findBookPriceByBid("1001"));
		bookShopDao.updateBookStock("1001");
		bookShopDao.updateUserAccount(101, 100.0);
	}

	@Test
	public void testPurchase(){
		bookShopService.purchase(101, "1001");
	}
	
	@Test
	public void testCheckOut(){
		cashier.checkout(101, Arrays.asList("1001","1002"));
	}
}
